package cn.antscrpt.antLib.test 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.display.BlendMode;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;
	
	
	
	
	public class Test extends Sprite {
		
		
		public static const IMG_PATH:String = "../lib/diaopai.png";
		private var _loader:Loader;
		
		
		private var _container:Sprite;
		
		public function Test():void {
			
			init();
			
			
		}
		
		private function init():void
		{
			loadImg();
			
			
		}
		
		private function createInteractive():void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
		}
		
		private function onMove(e:MouseEvent):void 
		{
			_container.rotationX = mouseX / stage.stageWidth * 180;
			_container.rotationY = mouseY / stage.stageHeight * 180;
		}
		
		private function createBmp(bitmap:Bitmap):void
		{
			_container = new Sprite();
			_container.x = stage.stageWidth / 2;
			_container.y = stage.stageHeight / 2;
			addChild(_container);
			
			var rBmp:BitmapData = new BitmapData(bitmap.width, bitmap.height, true, 0xff000000);
			var gBmp:BitmapData = new BitmapData(bitmap.width, bitmap.height, true, 0xff000000);
			var bBmp:BitmapData = new BitmapData(bitmap.width, bitmap.height, true, 0xff000000);
			
			rBmp.copyChannel(bitmap.bitmapData, bitmap.bitmapData.rect, new Point(), BitmapDataChannel.RED, BitmapDataChannel.RED);
			gBmp.copyChannel(bitmap.bitmapData, bitmap.bitmapData.rect, new Point(), BitmapDataChannel.GREEN, BitmapDataChannel.GREEN);
			bBmp.copyChannel(bitmap.bitmapData, bitmap.bitmapData.rect, new Point(), BitmapDataChannel.BLUE, BitmapDataChannel.BLUE);
			
			var rBitmap:Bitmap = new Bitmap(rBmp);
			rBitmap.x = -rBmp.width / 2;
			rBitmap.y = -rBitmap.height / 2;
			rBitmap.z = 0;
			_container.addChild(rBitmap);
			
			var gBitmap:Bitmap = new Bitmap(gBmp);
			gBitmap.x = -gBmp.width / 2;
			gBitmap.y = -gBitmap.height / 2;
			gBitmap.z = 50;
			_container.addChild(gBitmap);
			
			var bBitmap:Bitmap = new Bitmap(bBmp);
			bBitmap.x = -bBmp.width / 2;
			bBitmap.y = -bBitmap.height / 2;
			bBitmap.z = 100;
			_container.addChild(bBitmap);
			
			//_container.blendMode = new BlendMode.SCREEN;
		
			
		}
		
		private function loadImg():void
		{
			_loader = new Loader();
			_loader.load(new URLRequest(Test.IMG_PATH));
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCom);
		}
		
		private function onCom(e:Event):void 
		{
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onCom);
			
			createBmp(_loader.content as Bitmap);
			createInteractive();
		}		
		
		
		
		
		
		
	}
	
}